import tensorflow as tf
from numpy.random import RandomState

batch_size = 8

x = tf.placeholder(tf.float32, shape=(None, 1), name="x-input")

w1 = tf.Variable(tf.random_normal([1, 3], stddev=1, name="weight1", seed=1))

w2 = tf.Variable(tf.random_normal([3, 1], stddev=1, name="weight2", seed=1))

y_ = tf.placeholder(tf.float32, shape=(None, 1), name="y_input")

a = tf.matmul(x, w1)
y = tf.matmul(a, w2)

loss_less = 10
loss_more = 1

loss = tf.reduce_sum(tf.where(tf.greater(y, y_), (y-y_) * loss_more, (y_-y) * loss_less))

train_step = tf.train.AdadeltaOptimizer(0.001).minimize(loss)

rdm = RandomState(1)
dataset_size = 128

X = rdm.rand(dataset_size, 1)

Y = [x1 + rdm.rand()/10-0.05 for (x1) in X]

with tf.Session() as sess:
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    STEPS = 50000000000
    for i in range(STEPS):
        start = (i*batch_size) % dataset_size
        end = min(start + batch_size, dataset_size)
        # print(Y[start: end])
        # print(sess.run(y, feed_dict={x: X[start: end]}))
        sess.run(train_step, feed_dict={x: X[start: end], y_: Y[start: end]})
        print("-------------------")
        print(sess.run(loss, feed_dict={x: X, y_: Y}))


